package cn.idietrade.idietradegoodmanage8008.demo.controller;

import cn.idietrade.common.pojo.SecondGoods;
import cn.idietrade.common.pojo.SecondUser;
import cn.idietrade.common.utils.RedisUtil;
import cn.idietrade.common.utils.ReturnResultData;
import cn.idietrade.idietradegoodmanage8008.demo.service.GoodsManageService;
import cn.idietrade.idietradegoodmanage8008.demo.utils.RabbitMQUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;

import javax.annotation.Resource;


/**
 * @author 作者：李永康
 * @createTime 2022/12/5 14:15
 * @description 描述
 */
@RestController
public class GoodsManageController {
    @Resource
    private GoodsManageService goodsManageService;
//    @Resource
//    private RedisUtil redisUtil;

    @Resource
    private RabbitMQUtil rabbitMQUtil;
    @RequestMapping("/goodsUpdate")
    public ReturnResultData goodsupdate(@RequestParam Integer state,@RequestParam Integer id){
       // SecondUser secondUser = JSON.parseObject(redisUtil.getStr(token), SecondUser.class);
        ReturnResultData resultData = new ReturnResultData();
        int result = goodsManageService.goodsAudit(state, id);
        if(result>0){
            rabbitMQUtil.sendMessage("aa");
            resultData.setCode(1);
            resultData.setMessage("商品状态修改成功");
            resultData.setData(result);
        }else{
            resultData.setCode(0);
            resultData.setMessage("商品状态修改失败");
            resultData.setData(result);
        }
        return  resultData;
    }
    @RequestMapping("/getAllList")
    public PageInfo<SecondGoods> getList(@RequestParam(required = false) String goodsName,@RequestParam(required = false) Integer pageNum,@RequestParam(required = false) Integer pageSize){
        PageInfo<SecondGoods> list = goodsManageService.getList(goodsName,pageNum, pageSize);
        return list;
    }

}
